<template>
  <div>
    <d2-crud
      ref="d2Crud"
      :columns="columns"
      :data="historyTaskList"
      :options="options"
      :rowHandle="rowHandle"
      index-row
      selection-row
      @row-click="rowClick"
      @selection-change="selectChange"
      @del-model="delHistoryTask"
      @more-model="showDetail"
      >
    </d2-crud>
    <detail-info v-model="detailVisible" ref="detailFrom" @submit="getHistoryTask"/>
  </div>
</template>

<script>
  import workflowApi from '@/api/system/workflow';
  import zhzfUtils from '@/assets/utils/zhzf-util';
  import dictCache from '@/assets/utils/cache-dict-util';
  import detailInfo from "./detail-info";
  import HeadBtns from "@/views/comps/zhzf/head-btns";

  export default {
    name: 'history-task',
    components: {HeadBtns, detailInfo},
    data() {
      return {
        columns: [
          {title:'任务名称', key:'name'},
          {title: '发起人', key: 'owner'},
          {title: '发起时间', key: 'createTime',formatter: (row, col, val) => {
              return zhzfUtils.formatDts(val, 'YYYY-MM-DD HH:mm:ss')
            }
          },
          {title: '结束时间', key: 'endTime',formatter: (row, col, val) => {
              return zhzfUtils.formatDts(val, 'YYYY-MM-DD HH:mm:ss')
            }
          },
          {title: '处理人', key: 'assignee'},
          {title:'状态', key:'deleteReason'}
        ],
        rowHandle: {
          custom: [
            {title: '删除', size: 'mini', emit: 'del-model', icon: "el-icon-delete", style: "color:#f56c6c;"},
            {title: '更多', size: 'mini', emit: 'more-model', icon: "el-icon-more", style: "color:#67c23a;"},
          ]
        },
        options: {
          stripe: true,
          highlightCurrentRow: true
        },
        selected: [],
        detailVisible:false,
        historyTaskList:[],
      }
    },
    mounted() {
      this.getHistoryTask()
    },
    methods: {
      async getHistoryTask() {   //获取用户的任务历史记录
        let resp = await workflowApi.historyTaskPage();
        if (resp) {
          this.historyTaskList = resp.data;
        }
      },
      delHistoryTask(){ //删除历史任务
        window.event.stopPropagation(); //阻止冒泡
      },
      rowClick(row) {
        this.$refs.d2Crud.$children[0].toggleRowSelection(row);
      },
      selectChange(selection) {
        this.selected = selection;
      },
      showDetail({row}) {
        window.event.stopPropagation(); //阻止冒泡
        this.detailVisible = true;
        this.$refs.detailFrom.initPage(row);
      },
    }
  }
</script>

<style scoped lang="scss">
</style>
